//
//  AnimRootViewController.m
//  OCIOSDemo
//
//  Created by Caldremch on 2018/5/28.
//  Copyright © 2018年 Caldremch. All rights reserved.
//

#import "AnimRootViewController.h"
#import "AnimRowDetainViewController.h"

@interface AnimRootViewController ()

@end

@implementation AnimRootViewController

- (id) initWithStyle:(UITableViewStyle)style{
    
    self = [super initWithStyle:style];
    
    if (self) {
        self.title = @"IOS 动画";
    }
    
    return self;
}





- (void)viewDidLoad {
    [super viewDidLoad];
    
    viewAnimationArray =[NSArray arrayWithObjects: @"淡入、淡出", @"位置变换", @"缩放变换", @"旋转动画", @"代理动画", @"过渡动画", @"block 动画", nil];
    
    transitionArray = [NSArray arrayWithObjects:@"trainsition 1", @"trainsition 2", @"trainsition 3", @"trainsition 4", nil];
    

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0){
        return viewAnimationArray.count;
    }
    return [transitionArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    if (indexPath.section == 0) {
        cell.textLabel.text = [viewAnimationArray objectAtIndex:indexPath.row];
    }else{
        cell.textLabel.text = [transitionArray objectAtIndex:indexPath.row];
    }
    
    return cell;
    
    
    
    
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    
    if (section == 0) {
        return @"UIView Animation";
    }
    
    return @"Core Animation";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    AnimRowDetainViewController *ard  = [[AnimRowDetainViewController alloc] initWithNibName:nil bundle:nil];
    ard.section = indexPath.section;
    ard.row = indexPath.row;
    ard.title = (indexPath.section == 0)? [viewAnimationArray objectAtIndex:indexPath.row]:
    [transitionArray objectAtIndex:indexPath.section];
    
    CATransition *transition = [CATransition animation];
    transition.type = @"cube";
    transition.subtype = kCATransitionFromRight;
    transition.duration = 0.6;
    [self.navigationController.view.layer addAnimation:transition forKey:@"NavgationAnimation"];
    [self.navigationController pushViewController:ard animated:NO];
    
    
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
